package com.xingkeduo.business.user.controller;

import com.xingkeduo.business.transformation.json.ConsumerStatisticsJTO;
import com.xingkeduo.business.user.domain.ConsumerDomain;
import com.xingkeduo.pojo.dto.ConsumerStatisticsDTO;
import com.xingkeduo.pojo.utils.ResponseUtils;
import com.xingkeduo.util.pojo.base.BaseController;
import com.xingkeduo.util.tool.ReturnUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author:gaozifeng
 * @Date 2019/3/14 16:40
 **/
@RestController
@RequestMapping("/consumer/statistics")
public class ConsumerStatisticsController extends BaseController {

    @Autowired
    private ConsumerDomain consumerDomain;

    /**
     * 新增消费者统计记录
     *
     * @return : java.lang.String
     * @author : gaozifeng
     * @date : 2019/3/14 17:37
     * @desc 新增时 id，服务金额     必传
     */
    @PostMapping("/service")
    public String insert(@RequestBody ConsumerStatisticsDTO consumerStatisticsDTO) {
        returnUtil = new ReturnUtil();
        try {
            consumerDomain.insertConsumerStatistics(consumerStatisticsDTO);
            return returnUtil.getSuccess();
        } catch (Throwable t) {
            return dealException(t, returnUtil);
        }
    }

    /**
     * 查询用户是否新用户 现在是营销判断C拉C活动的
     *
     * @param id:
     * @return : org.springframework.http.ResponseEntity
     * @author : gaozifeng
     * @date : 2019/7/15 15:17
     */
    @PostMapping("/newComer")
    public ResponseEntity checkNewComer(@RequestBody String id) {
        returnUtil = new ReturnUtil();
        try {
            return new ResponseEntity<>(ResponseUtils.getSuccess(consumerDomain.checkNewComer(ConsumerStatisticsJTO.createQueryForPrimary(id))), HttpStatus.OK);
        } catch (Throwable t) {
            return new ResponseEntity<>(ResponseUtils.error(t.getMessage(), "-1"), HttpStatus.OK);
        }
    }

    /**
     * 订单--返回新用户集合
     *
     * @param consumerIds:
     * @return : org.springframework.http.ResponseEntity
     * @author : gaozifeng
     * @date : 2019/7/17 14:55
     */
    @PostMapping("/newConsumerList")
    public ResponseEntity newConsumerList(@RequestBody List<ConsumerStatisticsDTO> consumerIds) {
        returnUtil = new ReturnUtil();
        try {
            return new ResponseEntity<>(ResponseUtils.getSuccess(consumerDomain.newConsumerList(consumerIds)), HttpStatus.OK);
        } catch (Throwable t) {
            return new ResponseEntity<>(ResponseUtils.error(t.getMessage(), "-1"), HttpStatus.OK);
        }
    }

}
